#region Copyright (C) 2007 Jens Winter

//Copyright (C) 2007 Jens Winter

//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.

//This library is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//Lesser General Public License for more details.

//You should have received a copy of the GNU Lesser General Public
//License along with this library; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

#endregion

using System;
using System.Linq;
using Flynn.Core.Activities;
using Flynn.Core.ActivityResults;
using MbUnit.Framework;

namespace Flynn.Core.Tests.Activities
{
    [TestFixture]
    public class FilterUpdatesActivityFixture
    {
        private IFilterUpdatesActivity _filterUpdatesActivity;

        [SetUp]
        public void SetUp()
        {
            _filterUpdatesActivity = new FilterUpdatesActivity();
        }

        [Test]
        [ExpectedException(typeof (ArgumentNullException))]
        public void When_Filtering_Updates_Project_Must_Not_Be_Null()
        {
            _filterUpdatesActivity.FilterUpdates(null, "1", string.Empty);
        }

        [Test]
        public void Can_Filter_Updates_When_Project_Is_Empty()
        {
            Project project = new Project();

            FilterUpdatesResult result = _filterUpdatesActivity.FilterUpdates(project, string.Empty, string.Empty);

            Assert.IsFalse(result.Failed);
            Assert.IsEmpty(result.FilteredUpdates.ToList());
        }

        [Test]
        public void Can_Filter_Updates()
        {
            Update update1 = new Update("1");
            Update update2 = new Update("2");

            Project project = new Project();
            project.AddUpdate(update1);
            project.AddUpdate(update2);

            FilterUpdatesResult result = _filterUpdatesActivity.FilterUpdates(project, "1", string.Empty);

            Assert.IsFalse(result.Failed);
            Assert.AreEqual(1, result.FilteredUpdates.Count());
            Assert.AreEqual(update2, result.FilteredUpdates.ToList()[0]);
        }
    }
}